<?php
class dbclass {
    public $conn;
    public $sql;
    public $query;
    
   
    public function connect($arr) {
        $this->conn = mysql_connect($arr[0], $arr[1], $arr[2]);
        if (!$this->conn) {
            echo "Unable to connect to DB: " . mysql_error();
        exit;
        }
        return $this;
    }    
    
    public function select_db($db) {
        if (!mysql_select_db($db)) {
            echo "Unable to select mydbname: " . mysql_error();
        exit;
        }        
        return $this;
    }
        
    public function query($sql) {
        $this->query = $sql;
        $this->result = mysql_query($sql);

        if (!$this->result) {
            echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
        }        
        return $this;
    }
    
    public function fetch() {
        $arr = array();
        while ($row = mysql_fetch_assoc($this->result)) {
                $arr[] = $row; 
        }
        mysql_free_result($this->result);
        return $arr;
    }
    
}
?>
